package model

import (
	"encoding/json"
	"go.mongodb.org/mongo-driver/bson"
	"testing"
)

func TestRam_UnmarshalJSON(t *testing.T) {
	TestJsonSuits(
		t,
		[]Suit{
			{&Ram{Unit: "mb", Value: 25}, "\"25mb\""},
			{&Ram{Unit: "m", Value: 25}, "\"25m\""},
			{&Ram{}, "\"0\""},
			{&Ram{Unit: "gb", Value: 6234}, "\"6234gb\""},
		}, func(bytes []byte) (interface{}, error) {
			var reverse Ram
			err := json.Unmarshal(bytes, &reverse)

			return &reverse, err
		},
	)
}

func TestRam_UnmarshalBSONValue(t *testing.T) {
	TestBsonSuits(
		t,
		[]Suit{
			{&Ram{Unit: "mb", Value: 25}, "\"25mb\""},
			{&Ram{Unit: "m", Value: 25}, "\"25m\""},
			{&Ram{}, "\"0\""},
			{&Ram{Unit: "gb", Value: 6234}, "\"6234gb\""},
		}, func(value bson.RawValue) (interface{}, error) {
			var reverse Ram
			err := value.Unmarshal(&reverse)

			return &reverse, err
		},
	)
}
